package com.catsic.zcjc.dao.jdbc;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.catsic.base.dao.impl.JdbcBaseDaoImpl;
import com.catsic.zcjc.condition.EquipDataCondition;
import com.catsic.zcjc.enums.DataCountType;
import com.catsic.zcjc.form.StationCountForm;

@Repository("jdbcEquipDataDao")
public class JdbcEquipDataDao extends JdbcBaseDaoImpl<StationCountForm, Long>{

	@Override
	public StationCountForm get(Long id) {
		return null;
	}

	@Override
	public void add(StationCountForm t) {
		
	}

	@Override
	public void delete(Long id) {
		
	}

	@Override
	public void update(StationCountForm t) {
		
	}

	@Override
	public Integer getTotalCount() {
		return null;
	}

	@Override
	public List<StationCountForm> getList(int startIndex, int count) {
		return null;
	}

	@Override
	public List<StationCountForm> getAll() {
		return null;
	}

	public List<Map<String,Object>> getByCount(String type,EquipDataCondition condition) {
		String beginDate = condition.getBeginDate();
		String endDate = condition.getEndDate();
		
		String dateSql = "";
		if(StringUtils.isNotBlank(beginDate)){
			dateSql = dateSql +" and ed.collection_time>='"+beginDate+"' ";
		}
		if(StringUtils.isNotBlank(endDate)){
			dateSql = dateSql +" and ed.collection_time<='"+endDate+"' ";
		}
		
		String sql = "select s.id,s.name as areaName,s.latitude,s.longitude,count(*) as totalCount from T_EQUIP_DATA ed,T_STATION s where ed.STATION_ID = s.ID and ed.PLATE_NO is not null "+dateSql+" group by s.id,s.name,s.latitude,s.longitude order by s.code";
		if(DataCountType.weight.toString().equals(type)){
			sql = "select s.id,s.name as areaName,s.latitude,s.longitude,sum(ed.TOTAL_WEIGHT) as totalCount from T_EQUIP_DATA ed,T_STATION s where ed.STATION_ID = s.ID and ed.PLATE_NO is not null "+dateSql+" group by s.id,s.name,s.latitude,s.longitude order by s.code";
		}else if(DataCountType.overrun.toString().equals(type)){
			sql = "select s.id,s.name as areaName,s.latitude,s.longitude,sum(ed.TOTAL_WEIGHT*ed.OVERRUN_WEIGHT) as totalCount from T_EQUIP_DATA ed,T_STATION s where ed.STATION_ID = s.ID and ed.PLATE_NO is not null "+dateSql+" group by s.id,s.name,s.latitude,s.longitude order by s.code";
		}
		
		List<Map<String,Object>> list = this.jdbcTemplate.queryForList(sql);
		
		return list;
	}
}
